<template>
    <div>
        <a-modal
            :visible="handleModalVisible"
            title=""
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto'}"
            wrapClassName="internalControl-full-modal"
            @cancel="closeVisible"
            >
            <template slot="footer" style="text-align:center;">
                <div v-if="linkName == '我的已办'">
                    <a-button class="blue-btn" @click="closeVisible">关闭</a-button>
                </div>
                <div v-else>
                    <a-button @click="onSubmit('保存')">
                        保存
                    </a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '报销登记'" class="red-btn" @click="returnClick">
                        退回
                    </a-button>
                </div>
            </template>
            <a-tabs type="card">
                <a-tab-pane key="1" tab="申请表">
                    <a-form-model
                        ref="ruleForm"
                        :model="form"
                        :rules="rules"
                    >
                        <h1>报销申请</h1>
                        <table border="1" cellspacing="0" class="baoxiaoForm-table-Lu">
                            <tr>
                                <th>摘要</th>
                                <td colspan="3" v-if="linkName == '报销登记'">
                                    <a-form-model-item prop="fzy">
                                        <a-textarea  v-model="form.fzy" style="width: 100%;" placeholder="请输入摘要" :auto-size="{ minRows: 2}"/>
                                    </a-form-model-item>
                                </td>
                                <td v-else colspan="3" style="text-align: left;padding-left: 10px;">{{form.fzy}}</td>
                            </tr>
                            <tr>
                                <th>开始日期</th>
                                <td v-if="linkName == '报销登记'">
                                    <a-form-model-item prop="fksrq">
                                        <a-date-picker v-model="form.fksrq" @change="timeChange($event,'fksrq')" />
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{form.fksrq}}</td>
                                <th>结束日期</th>
                                <td  v-if="linkName == '报销登记'">
                                    <a-form-model-item prop="fjsrq">
                                        <a-date-picker v-model="form.fjsrq" @change="timeChange($event,'fjsrq')" />
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{form.fjsrq}}</td>
                            </tr>
                            <tr>
                                <th>合计天数</th>
                                <td  v-if="linkName == '报销登记'">
                                    <a-form-model-item>
                                        <a-input disabled placeholder="自动计算，无需填写" v-model="form.fhjts"/>
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{form.fhjts}}</td>
                                <th>是否预付款</th>
                                <td  v-if="linkName == '报销登记'">
                                    <a-form-model-item>
                                        <a-select v-model="form.fsfyfk" default-value="否" @change="fsfyfkChange">
                                            <a-select-option value="是">
                                                是
                                            </a-select-option>
                                            <a-select-option value="否">
                                                否
                                            </a-select-option>
                                        </a-select>
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{form.fsfyfk}}</td>
                            </tr>
                            <tr v-if="isFxmyszb()">
                                <th>项目预算指标</th>
                                <td colspan="3">
                                    <a-form-model-item  prop="fxmyszbid">
                                        <a-button v-if="isCheckData()" @click="addHandle" class="blue-btn" style="float: inline-start;">点击选择</a-button>
                                        <a-table
                                            v-if="yszbdataSource.length"
                                            bordered
                                            :data-source="yszbdataSource"
                                            :columns="yszbcolumns"
                                            :pagination="false">
                                        </a-table>
                                    </a-form-model-item>
                                </td>
                            </tr>
                            <tr>
                                <th>报销申请明细</th>
                                <td colspan="3">
                                    <div>
                                        <a-button v-if="linkName == '报销登记'" @click="addMxFormItem" class="blue-btn" style="float: inline-start;z-index: 99;">添加报销明细</a-button>
                                        <a-form-model-item>
                                            <a-table bordered :data-source="dataSource" :columns="linkName == '报销登记'?columns:columnsb" :pagination="false">
                                                <template v-if="linkName == '报销登记'" slot="operation_btn" slot-scope="text, record">
                                                    <a-button v-if="form.id" class="blue-btn" style="margin-right: 10px;" @click="editMxFormItem(record)">编辑</a-button>
                                                    <a-popconfirm
                                                        title="您确定要删除这条申请明细吗?"
                                                        ok-text="确定"
                                                        cancel-text="取消"
                                                        @confirm="removeFormItem(record)"
                                                        @cancel="cancel"
                                                        >
                                                            <a-button class="red-btn">删除</a-button>
                                                    </a-popconfirm>
                                                </template>
                                            </a-table>
                                        </a-form-model-item>
                                    </div>
                                </td>
                            </tr>
                                <tr>
                                    <th>部门审核</th>
                                    <td colspan="3">
                                        <a-form-model-item v-if="linkName == '部门审核'" prop="fksshyj" class="shenPi-item">
                                            <reviewOpinions ref="reviewOpinionsRefKs" @getInputOpinion="getInputOpinion" @openOpinions="ksOpinions"/>
                                        </a-form-model-item>
                                        <a-form-model-item v-else class="shenPi-item">
                                            <div class="shenPi-yj-item">
                                                <p>{{form.fksshyj}}</p>
                                                <div class="name-time-rightdiv">
                                                    <img v-if="getUrl('部门审核') && form.fksshyjsj" :src="getUrl('部门审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ form.fksshr }}</span>
                                                    <span>{{form.fksshyjsj}}</span>
                                                </div>
                                            </div>
                                        </a-form-model-item>
                                    </td>
                                </tr>
                                <tr>
                                    <th>财务审核</th>
                                    <td colspan="3">
                                        <a-form-model-item v-if="linkName == '财务审核'" prop="fcwshyj" class="shenPi-item">
                                            <reviewOpinions ref="reviewOpinionsRefCwsh" @getInputOpinion="getInputOpinion" @openOpinions="cwshOpinions"/>
                                        </a-form-model-item>
                                        <a-form-model-item v-else class="shenPi-item">
                                            <div class="shenPi-yj-item">
                                                <p>{{form.fcwshyj}}</p>
                                                <div class="name-time-rightdiv">
                                                    <img v-if="getUrl('财务审核') && form.fcwshyjsj" :src="getUrl('财务审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ form.fcwshr }}</span>
                                                    <span>{{form.fcwshyjsj}}</span>
                                                </div>
                                            </div>
                                        </a-form-model-item>
                                    </td>
                                </tr>
                                <tr>
                                    <th>中心领导审核</th>
                                    <td colspan="3">
                                        <a-form-model-item v-if="linkName == '中心领导审核'" prop="fzxldshyj" class="shenPi-item">
                                            <reviewOpinions ref="reviewOpinionsRefZxldsh" @getInputOpinion="getInputOpinion" @openOpinions="zxldshOpinions"/>
                                        </a-form-model-item>
                                        <a-form-model-item v-else class="shenPi-item">
                                            <div class="shenPi-yj-item">
                                                <p>{{form.fzxldshyj}}</p>
                                                <div class="name-time-rightdiv">
                                                    <img v-if="getUrl('中心领导审核') && form.fzxldshyjsj" :src="getUrl('中心领导审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ form.fzxldshr }}</span>
                                                    <span>{{form.fzxldshyjsj}}</span>
                                                </div>
                                            </div>
                                        </a-form-model-item>
                                    </td>
                                </tr>
                                <tr>
                                    <th>财务核销</th>
                                    <td colspan="3">
                                        <a-form-model-item v-if="linkName == '财务核销'" prop="fcwhxyj" class="shenPi-item">
                                            <reviewOpinions ref="reviewOpinionsRefCwhx" @getInputOpinion="getInputOpinion" @openOpinions="cwhxOpinions"/>
                                        </a-form-model-item>
                                        <a-form-model-item v-else class="shenPi-item">
                                            <div class="shenPi-yj-item">
                                                <p>{{form.fcwhxyj}}</p>
                                                <div class="name-time-rightdiv">
                                                    <img v-if="getUrl('财务核销') && form.fcwhxyjsj" :src="getUrl('财务核销')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ form.fcwhxr }}</span>
                                                    <span>{{form.fcwhxyjsj}}</span>
                                                </div>
                                            </div>
                                        </a-form-model-item>
                                    </td>
                                </tr>
                                <tr>
                                    <th>财务复核</th>
                                    <td colspan="3">
                                        <a-form-model-item v-if="linkName == '财务复核'" prop="fcwfhyj" class="shenPi-item">
                                            <reviewOpinions  ref="reviewOpinionsRefCwfh" @getInputOpinion="getInputOpinion" @openOpinions="cwfhOpinions"/>
                                        </a-form-model-item>
                                        <a-form-model-item v-else class="shenPi-item">
                                            <div class="shenPi-yj-item">
                                                <p>{{form.fcwfhyj}}</p>
                                                <div class="name-time-rightdiv">
                                                    <img v-if="getUrl('财务复核') && form.fcwfhyjsj" :src="getUrl('财务复核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ form.fcwfhr }}</span>
                                                    <span>{{form.fcwfhyjsj}}</span>
                                                </div>
                                            </div>
                                        </a-form-model-item>
                                    </td>
                                </tr>
                        </table>
                    </a-form-model>
                </a-tab-pane>
                <a-tab-pane v-if="linkName == '我的已办'" key="2" tab="流转记录">
                    <a-table
                        :columns="lzColumns"
                        :data-source="lzList"
                        bordered
                        style="border-color: #d9d9d9;font-weight: 600;text-align: center;"
                        :customRow="customRow">
                    </a-table>
                </a-tab-pane>
            </a-tabs>
        </a-modal>
        <selectDataModal ref="selectDataModalRef" @getSelectionValue="getSelectionValue"></selectDataModal>
        <baoXiaoMinfXiModal ref="baoXiaoMinfXiModalRef" :mxObj="mxObj" :dayNum="form.fhjts" @editFormItem="editFormItem" @addFormItem="addFormItem"></baoXiaoMinfXiModal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector'
import selectDataModal from './selectDataModal.vue'
import baoXiaoMinfXiModal from './baoXiaoMinfXiModal'
import { initBzFlow,saveFlow,submitFlow,mxAdd,mxDelte,mxEdit,
        selectbxmx,queryJobByJobId,returnUpperzdyFlowJob,flowJkPage,downMyQm,selectXmyszb} from './service/index'
import moment from 'moment'
export default {
    props:{
        passObj:{
            type:[Array,Object],
            default: () => {},
            required:false
        },
        linkName: {
            type:String,
            default: '',
            required:false
        }
    },
    components:{
        compSelector,selectDataModal,baoXiaoMinfXiModal
    },
    data() {
        return {
            moment:moment,
            handleModalVisible: false,
            labelCol: { span: 12 },
            wrapperCol: { span: 14 },
            form: {
                fbxlx: "",
                fccid: "",
                fcwfhr: "",
                fcwfhyj: "",
                fcwfhyjsj: "",
                fcwhxr: "",
                fcwhxyj: "",
                fcwhxyjsj: "",
                fcwshr: "",
                fcwshyj: "",
                fcwshyjsj: "",
                fhjts: null,
                fjsrq: null,
                fksrq: null,
                fksshr: "",
                fksshyj: "",
                fksshyjsj: "",
                flczt: "",
                fsfdlbx: "",
                fsffqlc: "",
                fsfyfk: "否",
                fsqrq: "",
                ftjr: "",
                ftjrbm: "",
                ftjrid: "",
                fxmyszbid: null,
                fzxldshr: "",
                fzxldshyj: "",
                fzxldshyjsj: "",
                fzy: "",
                id: "",
            },
            formItems: [],
            kongForm: {},
            rules: {
                fksrq: [{ required: true, message: '请输入开始日期', trigger: 'change' }],
                fjsrq: [{ required: true, message: '请输入结束日期', trigger: 'change' }],
                fzy: [{ required: true, message: '请输入摘要', trigger: 'blur' }],
                fxmyszbid: [{ required: true, message: '请选择项目预算指标', trigger: 'blur' }],

                fksshyj: [{ required: true, message: '请输入部门审核意见', trigger: 'blur' }],
                fcwshyj: [{ required: true, message: '请输入财务审核意见', trigger: 'blur' }],
                fzxldshyj: [{ required: true, message: '请输入中心领导审核意见', trigger: 'blur' }],
                fcwhxyj: [{ required: true, message: '请输入财务核销意见', trigger: 'blur' }],
                fcwfhyj: [{ required: true, message: '请输入财务复核意见', trigger: 'blur' }],

            },
            imgList: [
                {fhjmc:'报销登记',url: ''},
                {fhjmc:'部门审核',url: ''},
                {fhjmc:'财务审核',url: ''},
                {fhjmc:'中心领导审核',url: ''},
                {fhjmc:'财务核销',url: ''},
                {fhjmc:'财务复核',url: ''},
            ],
            dataSource: [],
            yszbdataSource: [],
            columns: [
                {
                    title: '一级分类',
                    dataIndex: 'fxmdl',
                },{
                    title: '二级分类',
                    dataIndex: 'fxmxl',
                },{
                    title: '天数',
                    dataIndex: 'fts',
                },{
                    title: '金额',
                    dataIndex: 'fje',
                },{
                    title: '项目说明',
                    dataIndex: 'fxmsm',
                },{
                    title: '申请人姓名',
                    dataIndex: 'fsqrxm',
                },{
                    title: '操作',
                    dataIndex: 'jobid',
                    scopedSlots: { customRender: 'operation_btn' },
                }
            ],
            columnsb: [
                {
                    title: '一级分类',
                    dataIndex: 'fxmdl',
                },{
                    title: '二级分类',
                    dataIndex: 'fxmxl',
                },{
                    title: '天数',
                    dataIndex: 'fts',
                },{
                    title: '金额',
                    dataIndex: 'fje',
                },{
                    title: '项目说明',
                    dataIndex: 'fxmsm',
                },{
                    title: '申请人姓名',
                    dataIndex: 'fsqrxm',
                }
            ],
            yszbcolumns: [
                {
                    title: '部门',
                    dataIndex: 'fbm',
                },{
                    title: '预算项目名称',
                    dataIndex: 'fysxmmc',
                },{
                    title: '总指标',
                    dataIndex: 'fzzb',
                },{
                    title: '指标结余',
                    dataIndex: 'fzbjy',
                },
            ],
            mxObj:{},
            lzColumns: [
                {
                title: '环节名称',
                dataIndex: 'fhjmc',
                key: 'fhjmc',
                width: 150,
                },{
                title: '待办人',
                dataIndex: 'fdbr',
                key: 'fdbr',
                width: 100,
                },{
                title: '办理人',
                dataIndex: 'fblr',
                key: 'fblr',
                width: 100,
                },{
                title: '发送时间',
                dataIndex: 'ffssj',
                key: 'ffssj',
                width: 170,
                },{
                title: '办理时间',
                dataIndex: 'fblsj',
                key: 'fblsj',
                width: 170,
                },{
                title: '办理状态',
                dataIndex: 'fblzt',
                key: 'fblzt',
                width: 100,
                },{
                title: '办理类型',
                dataIndex: 'fbllx',
                key: 'fbllx',
                width: 300,
                },{
                title: '办理意见',
                dataIndex: 'fblyj',
                key: 'fblyj',
                },
            ],
            lzList: [],
        }
    },
    created() {
        this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    watch: {
        passObj(newval,oldVal){
            //console.log(newval)
            if(newval.id){
                this.form = newval
                this.getMxList(newval.id)
                this.getLiuZuanData(newval.id)
                this.getXmyszb(newval.ftjrid,newval.fxmyszbid)
            }
        },
    },
    methods: {
        // 右上角关闭后的回调
        closeVisible(e){
            this.$emit('success')
            this.handleModalVisible = false
            this.form = {...this.kongForm}
            this.formItems = []
            this.dataSource = []
            this.yszbdataSource = []
        },
        customRow() {
            return {
                style: {
                    'font-size' : '16px',
                    'text-align' : 'center'
                },
            }
        },
        isFxmyszb(){
            if(this.linkName == '报销登记' && this.form.fsfyfk == '是'){
                return true
            } else if(this.linkName == '财务核销' && this.form.fsfyfk == '否'){
                return true
            } else if(this.form.fsfyfk == '是'){
                return true
            } else {
                return false
            }
        },
        isCheckData(){
            if(this.linkName == '报销登记' && this.form.fsfyfk == '是'){
                return true
            } else if(this.linkName == '财务核销' && this.form.fsfyfk == '否'){
                return true
            } else {
                return false
            }
        },
        getMxList(id){
            selectbxmx({id:id}).then(res => {
                //console.log(res)
                this.formItems = res.result
                this.dataSource = res.result
            })
        },
        fsfyfkChange(val){
            if(val == '否'){
                this.form.fxmyszbid = ''
                this.yszbdataSource = []
            }
        },
        timeChange(val,name){
            let data = this.form
            data[name] = val == null?null:moment(val).format('YYYY-MM-DD')
            if(this.form.fksrq !== null && this.form.fjsrq !== null){
                let start = new Date(Date.parse(this.form.fksrq));
                let end = new Date(Date.parse(this.form.fjsrq));
                let diff = end.getTime() - start.getTime();// 两个日期相差的毫秒数
                let days = Math.floor(diff / (1000 * 60 * 60 * 24))
                if(days <= 0){
                    this.$message.warning('合计天数为'+`${days}`+',填写错误，请重新输入！')
                    this.this.form.fksrq = null
                    this.this.form.fjsrq = null
                } else {
                    this.form.fhjts = days
                }
            } else {
                this.form.fhjts = null
            }
        },
        getXmyszb(ids,zbid){
            //console.log()
            let data = {
                fxmyszbid: zbid,
                // tjrid: ids
            }
            selectXmyszb(data).then(res => {
                this.yszbdataSource = res.result
            })
        },
        getLiuZuanData(id){
            flowJkPage({oaid:id}).then(res => {
                let arr1 = []
                    arr1 = res.result.records
                var arr2 = new Array();
                for (let i = arr1.length - 1; i >= 0; i--) {
                arr2.push(arr1[i]);
                }
                // //console.log('arr2',arr2)
                this.lzList = []
                arr2.forEach(item => {
                item = {
                    ...item,
                    key: item.jobid
                }
                this.lzList.push(item)
                //console.log('IMG')
                this.imgList.forEach((items,a)=> {
                        if(item.fdbrid){
                        if(items.fhjmc == item.fhjmc){
                            downMyQm({id:item.fdbrid}).then(resa => {
                              if(resa.code){
                                this.imgList[a].url = null
                              } else {
                                this.imgList[a].url = "data:image/png;base64," +
                                btoa( new Uint8Array(resa).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                              }
                            })
                        }
                        } else {}
                    })
                    // //console.log('this.imgList',this.imgList)
                })
            })
        },
        getUrl(ids){
            let url = ''
            this.imgList.forEach(item => {
                if(item.fhjmc == ids){
                url = item.url
                }
            })
            return url
        },
        addMxFormItem(){
            this.$nextTick(_ => {
                this.$refs.baoXiaoMinfXiModalRef.handleModalVisible = true
            })
        },
        editMxFormItem(item){
            this.mxObj = {
                ...item,
            }
            this.$nextTick(_ => {
                this.$refs.baoXiaoMinfXiModalRef.handleModalVisible = true
            })
        },
        async addFormItem(item){
            if(this.form.id){
                let data = {
                    ...item,
                    fbxsqid: this.form.id
                }
                mxAdd(data).then(res => {
                    //console.log(res)
                    if(res.code == 200){
                        this.getMxList(this.form.id)
                    } else {
                        this.$message.warning(res.message)
                    }
                })
            } else {
                let data = {
                    fhjts: this.form.fhjts,
                    fjsrq: this.form.fjsrq,
                    fksrq: this.form.fksrq,
                    fsfyfk: this.form.fsfyfk,
                    fzy: this.form.fzy,
                    id: this.form.id
                }
                const resA = await initBzFlow(data)
                if(resA.code == 200){
                    this.form.id = resA.result.nkMap.id
                    this.form.jobid = resA.result.jobMap.id
                    let data = {
                        ...item,
                        fbxsqid: this.form.id
                    }
                    mxAdd(data).then(res => {
                        //console.log(res)
                        if(res.code == 200){
                            this.getMxList(this.form.id)
                        } else {
                            this.$message.warning(res.message)
                        }
                    })
                }
            }
        },
        editFormItem(item){
            mxEdit(item).then(res => {
                //console.log(res)
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.getMxList(this.form.id)
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        removeFormItem(item) {
            mxDelte({id:item.id}).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.getMxList(this.form.id)
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        addHandle(){
            this.$nextTick(_ => {
                this.$refs.selectDataModalRef.visible = true
            })
        },
        getSelectionValue(item){
            //console.log(item)
            this.form.fxmyszbid = item.id
            //console.log(this.form.fxmyszbid)
            this.yszbdataSource = []
            this.yszbdataSource.push(item)
            let data = {
                fhjts: this.form.fhjts,
                fjsrq: this.form.fjsrq,
                fksrq: this.form.fksrq,
                fsfyfk: this.form.fsfyfk,
                fzy: this.form.fzy,
                id: this.form.id,
                fxmyszbid: this.form.fxmyszbid
            }
            this.initBzFlowFuntion(data,'保存')
        },
        // 打开意见弹窗
        ksOpinions(){
            this.$refs.reviewOpinionsRefKs.getData({opinionType:'ksIdeaType',oldVal:this.form.fksshyj,valueData:{hjmc:'fksshyj'}})
        },
        cwshOpinions(){
            this.$refs.reviewOpinionsRefCwsh.getData({opinionType:'cwshIdeaType',oldVal:this.form.fcwshyj,valueData:{hjmc:'fcwshyj'}})
        },
        zxldshOpinions(){
            this.$refs.reviewOpinionsRefZxldsh.getData({opinionType:'zxldshIdeaType',oldVal:this.form.fzxldshyj,valueData:{hjmc:'fzxldshyj'}})
        },
        cwhxOpinions(){
            this.$refs.reviewOpinionsRefCwhx.getData({opinionType:'cwhxIdeaType',oldVal:this.form.fcwhxyj,valueData:{hjmc:'fcwhxyj'}})
        },
        cwfhOpinions(){
            this.$refs.reviewOpinionsRefCwfh.getData({opinionType:'cwfhIdeaType',oldVal:this.form.fcwfhyj,valueData:{hjmc:'fcwfhyj'}})
        },
        // 意见弹窗
        getInputOpinion(val,valueData){
            let data = this.form
            data[valueData.hjmc] = val
        },
        onSubmit(str) {
            if(this.dataSource.length){
                this.$refs.ruleForm.validate(valid => {
                    if (valid) {
                        let data= {}
                        if(str == '保存'){
                            if(this.linkName == '报销登记'){
                                if(this.form.id){
                                    data = {
                                        fhjts: this.form.fhjts,
                                        fjsrq: this.form.fjsrq,
                                        fksrq: this.form.fksrq,
                                        fsfyfk: this.form.fsfyfk,
                                        fzy: this.form.fzy,
                                        id: this.form.id,
                                        fxmyszbid: this.form.fxmyszbid?this.form.fxmyszbid:''
                                    }
                                    this.initBzFlowFuntion(data,str)
                                } else {
                                    data = {
                                        fhjts: this.form.fhjts,
                                        fjsrq: this.form.fjsrq,
                                        fksrq: this.form.fksrq,
                                        fsfyfk: this.form.fsfyfk,
                                        fzy: this.form.fzy,
                                        id: this.form.id,
                                        fxmyszbid: this.form.fxmyszbid?this.form.fxmyszbid:''
                                    }
                                    this.initBzFlowFuntion(data,str)
                                }
                            } else if(this.linkName == '部门审核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fksshyj: this.form.fksshyj,
                                        fksshr: this.form.fksshr,
                                        fksshyjsj: this.form.fksshyjsj
                                    },
                                    opinion: this.form.fksshyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.saveFlowFuntion(data)
                            } else if(this.linkName == '财务审核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fcwshyj: this.form.fcwshyj,
                                        fcwshr: this.form.fcwshr,
                                        fcwshyjsj: this.form.fcwshyjsj
                                    },
                                    opinion: this.form.fcwshyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.saveFlowFuntion(data)
                            } else if(this.linkName == '中心领导审核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fzxldshyj: this.form.fzxldshyj,
                                        fzxldshr: this.form.fzxldshr,
                                        fzxldshyjsj: this.form.fzxldshyjsj
                                    },
                                    opinion: this.form.fzxldshyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.saveFlowFuntion(data)
                            } else if(this.linkName == '财务核销'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fcwhxyj: this.form.fcwhxyj,
                                        fcwhxr: this.form.fcwhxr,
                                        fcwhxyjsj: this.form.fcwhxyjsj,
                                        fxmyszbid: this.form.fxmyszbid,
                                    },
                                    opinion: this.form.fcwhxyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.saveFlowFuntion(data)
                            } else if(this.linkName == '财务复核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fcwfhyj: this.form.fcwfhyj,
                                        fcwfhr: this.form.fcwfhr,
                                        fcwfhyjsj: this.form.fcwfhyjsj
                                    },
                                    opinion: this.form.fcwfhyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.saveFlowFuntion(data)
                            }
                        } else if(str == '提交'){
                            if(this.linkName == '报销登记'){
                                if(this.form.id){
                                    data = {
                                        jobid: this.form.jobid,
                                        oaid: this.form.id,
                                        map: {
                                            fhjts: this.form.fhjts,
                                            fjsrq: this.form.fjsrq,
                                            fksrq: this.form.fksrq,
                                            fsfyfk: this.form.fsfyfk,
                                            fzy: this.form.fzy,
                                            fxmyszbid: this.form.fxmyszbid?this.form.fxmyszbid:''
                                            // id: this.form.id
                                        },
                                        opinion: this.form.fksshyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    this.submitFlowFuntion(data)
                                } else {
                                    data = {
                                        id: '',
                                        fhjts: this.form.fhjts,
                                        fjsrq: this.form.fjsrq,
                                        fksrq: this.form.fksrq,
                                        fsfyfk: this.form.fsfyfk,
                                        fzy: this.form.fzy,
                                        fsffqlc: '是',
                                        fxmyszbid: this.form.fxmyszbid?this.form.fxmyszbid:''
                                    }
                                    this.initBzFlowFuntion(data,str,'1')
                                }
                            } else if(this.linkName == '部门审核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fksshyj: this.form.fksshyj,
                                        fksshr: this.form.fksshr,
                                        fksshyjsj: this.form.fksshyjsj
                                    },
                                    opinion: this.form.fksshyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.submitFlowFuntion(data)
                            } else if(this.linkName == '财务审核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fcwshyj: this.form.fcwshyj,
                                        fcwshr: this.form.fcwshr,
                                        fcwshyjsj: this.form.fcwshyjsj
                                    },
                                    opinion: this.form.fcwshyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.submitFlowFuntion(data)
                            } else if(this.linkName == '中心领导审核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fzxldshyj: this.form.fzxldshyj,
                                        fzxldshr: this.form.fzxldshr,
                                        fzxldshyjsj: this.form.fzxldshyjsj
                                    },
                                    opinion: this.form.fzxldshyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.submitFlowFuntion(data)
                            } else if(this.linkName == '财务核销'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fcwhxyj: this.form.fcwhxyj,
                                        fcwhxr: this.form.fcwhxr,
                                        fcwhxyjsj: this.form.fcwhxyjsj,
                                        fxmyszbid: this.form.fxmyszbid,
                                    },
                                    opinion: this.form.fcwhxyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.submitFlowFuntion(data)
                            } else if(this.linkName == '财务复核'){
                                data = {
                                    jobid: this.form.jobid,
                                    oaid: this.form.id,
                                    map: {
                                        fcwfhyj: this.form.fcwfhyj,
                                        fcwfhr: this.form.fcwfhr,
                                        fcwfhyjsj: this.form.fcwfhyjsj
                                    },
                                    opinion: this.form.fcwfhyj,
                                    currentNode: "",
                                    dbrid: "",
                                    lcmbCode: "",
                                    nextNode: "",
                                    nextNodeId: "",
                                    smgflag: ""
                                }
                                this.submitFlowFuntion(data)
                            }
                        }
                    } else {
                        //console.log('error submit!!');
                        return false;
                    }
                });
            } else {
                this.$message.warning('请填写报销申请明细')
            }
        },
        // 退回
        returnClick(){
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    queryJobByJobId({jobid:this.form.jobid}).then(res => {
                        let list = res.result.jobHistoryList
                        list.forEach(item => {
                            if(item.fhjmc == '报销登记'){
                                this.returnFuntion(this.form.jobid,item.id)
                            }
                        })
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '部门审核'){
                returnStr = this.form.fksshyj
            } else if(this.linkName == '财务审核'){
                returnStr = this.form.fcwshyj
            } else if(this.linkName == '中心领导审核'){
                returnStr = this.form.fzxldshyj
            } else if(this.linkName == '财务核销'){
                returnStr = this.form.fcwhxyj
            } else if(this.linkName == '财务复核'){
                returnStr = this.form.fcwfhyj
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
            })
        },
        mxAddFuntion(){
            this.formItems.forEach(item => {
                item.fbxsqid = this.form.id
                let data = item
                mxAdd(data).then(res => {
                    //console.log(res)
                })
            })
        },
        initBzFlowFuntion(data,str){
            //console.log('44411',data)
            initBzFlow(data).then(res => {
                //console.log('555')
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.form.id = res.result.nkMap.id
                    this.form.jobid = res.result.jobMap.id
                    if(str == '提交'){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        saveFlowFuntion(data){
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        submitFlowFuntion(data){
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        cancel(){},
    },
}
</script>
<style>
@import url('../../../css/internal-control.css');
</style>
